package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/10 15:44
 * @description
 */
public class Code328 {
    private List<Integer> l1 = new ArrayList<>();
    private List<Integer> l2 = new ArrayList<>();

    public ListNode oddEvenList(ListNode head) {
        setList(head, 1);
        l1.addAll(l2);
        setNode(head, 0);
        return head;
    }

    private void setList(ListNode node, int level) {
        if (node != null) {
            if (level % 2 == 1) {
                l1.add(node.val);
            } else {
                l2.add(node.val);
            }
            setList(node.next, level += 1);
        }
    }

    private void setNode(ListNode node, int level) {
        if (node != null) {
            node.val = l1.get(level);
            setNode(node.next, level += 1);
        }
    }

}
